//获取所有父类
function parentCat(catPno) {
	var param = new Array();
	var initCatPno = catPno;
	if(catPno!='0'){
		param = {"catNo":catPno};
	}else{
		param = {"catPno":"0"};
	};
	
	var isBreak = true;
	var selected = "";
	for (var i = 1; i < 10; i++) {
		var ist = i%2 == 0;
		$.post(basePath + '/product/cat/getAjaxNextCommodityCat.do', param,
				function(data) {
					if (data != "") {
						var obj = $.parseJSON(data);
						catPno = obj[0].catPno;
						if(ist){
							var t = "<select name='level' onchange='getProCat(this);'>";
							if(catPno == '0'){
								t+="<option value='0'>请选择</option>";
							}else{
								t+="<option value=''>请选择</option>";
							}
							
							for ( var i = 0; i < obj.length; i++) {
								if (selected == obj[i].catNo) {
									t+="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+"' selected='selected'>"+obj[i].catName+"</option>";
								} else {
									t+="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+"'>"+obj[i].catName+"</option>";
								};
							}
							t+="</select>";
							$("#catDiv").prepend(t);
							param = {"catNo" : catPno};
							if(catPno == '0') isBreak =  false;
						}else{
							if(initCatPno!='0'){
								selected = obj[0].catNo;
								param = {"catPno":catPno};
							}
						}
					} else {
						return false;
					};
				}
		);
		if(!isBreak) return isBreak;
	};
};

//获取下一级所属子类  val:分类编码
function sonCat(val){
	if(val == "" || val == null) return false;
	$.post(
			basePath + '/product/cat/getAjaxNextCommodityCat.do', 
			{"catPno" : val}, 
			function(data) {
				if(data != ""){
					var obj=$.parseJSON(data);
					var t = "<select name='level' onchange='getProCat(this);'>";
					t += "<option value=''>请选择</option>";
					for(var i in obj){
						t +="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+"'>"+obj[i].catName+"</option>"; 
					};
					t += "<select>";
					$("#catDiv").append(t);
				};
			}
	);
}

//只读分类  catPno上一级分类编码
function readonlyCat(catPno) {
	var cat = catPno;
	var li = "<li id='"+cat+"'><input type='hidden' name='catNos' value='"+cat+"'></li>";
	$("#addcat").append(li);
	for ( var i = 1; i < 10; i++) {
		if(catPno == '0' && i == 1){
			var t = "<select disabled='disabled'><option>顶级分类</option></select>&nbsp;&nbsp;";
			$("#catDiv").append(t);
			return false;
		}
		if(catPno == '0'){
			return false;
		};
		$.post(basePath + '/product/cat/getAjaxNextCommodityCat.do', {
			catNo : catPno
		}, function(data) {
			if(data != ""){
				var obj=$.parseJSON(data);
				
				if($("#addcat").html() != null){
					var outText = "";
					outText += "<select disabled='disabled'><option>"+obj[0].catName+"</option></select>";
					$("#"+cat).prepend(outText);
				}else{
					var t = "<select disabled='disabled'><option>"+obj[0].catName+"</option></select>&nbsp;&nbsp;";
					$("#catDiv").after(t);
				}
				catPno = obj[0].catPno;
				if(obj[0].catPno == "0"){
					var del = '<a href="#" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">删除 </a>';
					$("#"+cat).append(del);
					return false;
				}
			}else{
				return false;
			};
		});
	};
}